<template>
  <div>
    <puplic-modal
      width="500px"
      :publicVisible="publicVisible"
      modalStyle="addEditSupportModal"
      @cancel="cancel"
      @handleOk="handleOk"
      :title="title"
    >
      <div slot="content" class="content">
        <div class="search-group" style="width: 100%">
          <div class="input-wrap" style="width: 100%">
            <div class="label xing">类型名称:</div>
            <div class="input-item" style="width: 90%">
              <a-input :maxLength="10" clearable v-model="industryExamineName" placeholder="请输入类型名称" />
            </div>
          </div>
        </div>

        <div class="search-group" style="width: 100%; margin: 20px 0">
          <div class="input-wrap" style="width: 100%">
            <div class="label xing" style="max-width: 60px">检查任务逾期天数:</div>
            <div class="input-item" style="width: 100%">
              <a-input :maxLength="3" clearable v-model="checkExpireCount" placeholder="请输入检查任务逾期天数" />
            </div>
          </div>
        </div>

        <div class="search-group" style="width: 100%">
          <div class="input-wrap" style="width: 100%">
            <div class="label xing" style="max-width: 60px">复查任务逾期天数:</div>
            <div class="input-item" style="width: 100%">
              <a-input :maxLength="3" clearable v-model="reviewExpireCount" placeholder="请输入复查任务逾期天数" />
              <!-- @change="this.$forceUpdate()" -->
            </div>
          </div>
        </div>
      </div>
    </puplic-modal>
  </div>
</template>
<script>
import puplicModal from '@/components/publicModal'
import { examineAdd, examineEdit } from '@/api/industry'
export default {
  components: { puplicModal },
  name: 'addEditSupportModal',
  data () {
    return {
      title: '新增检查类型',
      publicVisible: false,
      id: '',
      checkExpireCount: '',
      reviewExpireCount: '',
      industryExamineName: '',
      industryInformationId: '',
      records: {},
    }
  },
  methods: {
    show (records) {
      console.log(records)
      this.records = records
      this.publicVisible = true
      this.industryInformationId = records.industryInformationId

      if (records && records.id) {
        this.title = '编辑检查类型'
        this.id = records.id
        this.checkExpireCount = records.checkExpireCount
        this.reviewExpireCount = records.reviewExpireCount
        this.industryExamineName = records.industryExamineName
      } else {
        this.title = '新增检查类型'
      }
    },

    async handleOk () {
      if (this.industryExamineName == '') {
        this.$message.error('请输入类型名称')
        return
      }

      if (this.checkExpireCount == '') {
        this.$message.error('请输入检查任务逾期天数')
        return
      }
      let reg = /^(0|\+?[1-9][0-9]{0,2})$/
      if (reg.test(this.checkExpireCount) == false) {
        this.$message.warn('检查任务逾期天数只支持输入小于等于三位的正整数')
        return
      }

      if (this.reviewExpireCount == '') {
        this.$message.error('请输入复查任务逾期天数')
        return
      }
      if (reg.test(this.reviewExpireCount) == false) {
        this.$message.warn('复查任务逾期天数只支持输入小于等于三位的正整数')
        return
      }

      let data = {
        id: this.id || '',
        checkExpireCount: this.checkExpireCount,
        reviewExpireCount: this.reviewExpireCount,
        industryExamineName: this.industryExamineName,
        industryInformationId: this.industryInformationId,
      }
      if (this.title == '新增检查类型') {
        let res = await examineAdd(data)
        this.$message.success(res.message)
        this.cancel()
        this.$emit('refresh')
      } else {
        let res = await examineEdit(data)
        this.$message.success(res.message)
        this.cancel()
        this.$emit('refresh')
      }
    },
    cancel () {
      this.publicVisible = false
      this.checkExpireCount = ''
      this.reviewExpireCount = ''
      this.industryExamineName = ''
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/common.less';

/deep/ .content {
  padding: 20px;
}
.search-group {
  padding: 0;
}
</style>
